package org.benetech.beans.error;

import java.io.File;

import org.benetech.util.PreviewContext;


/**
 * A validation violation related to an XML file. Contains information about
 * the problem, and the location of the problem.
 *
 * @author Reuben Firmin
 */
public final class XMLValidationError implements ValidationError {

    private int lineNumber;
    private int columnNumber;
    private String message;
    private String systemId;
    private File errorContext;
    private PreviewContext previewContext;
    private Severity severity;

    /**
     * @param lineNumber The line number of the error.
     * @param columnNumber The column number of the error.
     * @param message The parser message.
     * @param systemId The full file name.
     * @param errorContext The relative file name.
     * @param severity The severity of the violation.
     */
    public XMLValidationError(final int lineNumber, final int columnNumber, final String message, final String systemId,
    		final File errorContext, final Severity severity)
    {
        this.lineNumber = lineNumber;
        this.columnNumber = columnNumber;
        this.message = message;
        this.systemId = systemId;
        this.errorContext = errorContext;
        this.severity = severity;
    }

    /**
     * Set the preview context of this violation, i.e. the segment of XML that
     * the problem was discovered in.
     * @param context Never null
     */
    public void setPreviewContext(final PreviewContext context) {
        this.previewContext = context;
    }

    /**
     * The column number of the error.
     * @return gte 0
     */
    public int getColumnNumber() {
        return columnNumber;
    }

    /**
     * The context of the error, i.e. a human readable version of the file name.
     * @return never null
     */
    public File getErrorContext() {
        return errorContext;
    }

    /**
     * The line number of the error.
     * @return gte 0
     */
    public int getLineNumber() {
        return lineNumber;
    }

    /**
     * The message returned by the parser.
     * @return never null
     */
    public String getMessage() {
        return message;
    }

    /**
     * The system id, i.e. the full path to the file name.
     * @return never null
     */
    public String getSystemId() {
        return systemId;
    }

    /**
     * {@inheritDoc}
     */
    public String toString() {
        return " Context: " + getErrorContext() + " Line: " + getLineNumber() + " Column: " + getColumnNumber()
        	+ " Message: " + getMessage() + " System Id: " + getSystemId();
    }

    /**
     * {@inheritDoc}
     */
    public Severity getSeverity() {
        return severity;
    }

    /**
     * Get the segment of XML code that the problem was found in.
     * @return Null if it hasn't been set.
     */
    public PreviewContext getPreviewContext() {
        return previewContext;
    }
}
